package com.flc.gateway.comm.data;

import com.flc.gateway.utils.ByteUtils;

/**
 * 轨迹数据的格式
 * @author haizi
 * @date 2018/1/1
 */
public class DiagnosisData {
    /**
     * 设置所有数据
     * @param bytes 轨迹数据的字节数组
     */
    public void setData(byte[] bytes) {

        this.setPVER(bytes[0]);
        this.setMsgType(bytes[1]);
        this.setEncrypt(bytes[2]);
        this.setVIN(ByteUtils.getStringWithIndex(bytes, 3, 17));
        this.setRTC(ByteUtils.getLong32WithIndex(bytes, 20));
        this.setEVID(ByteUtils.getShort16WithIndex(bytes, 24));
        this.setIDENT(ByteUtils.getStringWithIndex(bytes, 26, 15) );
        this.setGSM_SS(bytes[41]);
        this.setGSM_RS(bytes[42]);
        this.setPOS_SATS(bytes[43]);
        this.setPOS_VAL(bytes[44]);
        this.setPOS_LAT(ByteUtils.getFloatWithIndex(bytes,45));
        this.setPOS_LON(ByteUtils.getFloatWithIndex(bytes,49));
        this.setPOS_HDG(ByteUtils.getShort16WithIndex(bytes, 53));
        this.setPOS_ALT(ByteUtils.getShort16WithIndex(bytes, 55));
        this.setPOS_SPD(ByteUtils.getShort8WithIndex(bytes, 57));
        this.setODOM(ByteUtils.getLong32WithIndex(bytes, 58));
        this.setACC_VAL_X(ByteUtils.getShort16WithIndex(bytes, 62));
        this.setACC_VAL_Y(ByteUtils.getShort16WithIndex(bytes, 64));
        this.setACC_VAL_Z(ByteUtils.getShort16WithIndex(bytes, 66));
        this.setBAT_V(bytes[68] + bytes[69] * 0.1f);
    }

    /** ...... getters and setters ...... */
    public byte getPVER() {
        return PVER;
    }

    public void setPVER(byte PVER) {
        this.PVER = PVER;
    }

    public byte getMsgType() {
        return MsgType;
    }

    public void setMsgType(byte msgType) {
        MsgType = msgType;
    }

    public byte getEncrypt() {
        return Encrypt;
    }

    public void setEncrypt(byte encrypt) {
        Encrypt = encrypt;
    }

    public String getVIN() {
        return VIN;
    }

    public void setVIN(String VIN) {
        this.VIN = VIN;
    }

    public long getRTC() {
        return RTC;
    }

    public void setRTC(long RTC) {
        this.RTC = RTC;
    }

    public short getEVID() {
        return EVID;
    }

    public void setEVID(short EVID) {
        this.EVID = EVID;
    }

    public String getIDENT() {
        return IDENT;
    }

    public void setIDENT(String IDENT) {
        this.IDENT = IDENT;
    }

    public byte getGSM_SS() {
        return GSM_SS;
    }

    public void setGSM_SS(byte GSM_SS) {
        this.GSM_SS = GSM_SS;
    }

    public byte getGSM_RS() {
        return GSM_RS;
    }

    public void setGSM_RS(byte GSM_RS) {
        this.GSM_RS = GSM_RS;
    }

    public short getPOS_SATS() {
        return POS_SATS;
    }

    public void setPOS_SATS(short POS_SATS) {
        this.POS_SATS = POS_SATS;
    }

    public byte getPOS_VAL() {
        return POS_VAL;
    }

    public void setPOS_VAL(byte POS_VAL) {
        this.POS_VAL = POS_VAL;
    }

    public float getPOS_LAT() {
        return POS_LAT;
    }

    public void setPOS_LAT(float POS_LAT) {
        this.POS_LAT = POS_LAT;
    }

    public float getPOS_LON() {
        return POS_LON;
    }

    public void setPOS_LON(float POS_LON) {
        this.POS_LON = POS_LON;
    }

    public int getPOS_HDG() {
        return POS_HDG;
    }

    public void setPOS_HDG(int POS_HDG) {
        this.POS_HDG = POS_HDG;
    }

    public int getPOS_ALT() {
        return POS_ALT;
    }

    public void setPOS_ALT(int POS_ALT) {
        this.POS_ALT = POS_ALT;
    }

    public int getPOS_SPD() {
        return POS_SPD;
    }

    public void setPOS_SPD(int POS_SPD) {
        this.POS_SPD = POS_SPD;
    }

    public long getODOM() {
        return ODOM;
    }

    public void setODOM(long ODOM) {
        this.ODOM = ODOM;
    }

    public short getACC_VAL_X() {
        return ACC_VAL_X;
    }

    public void setACC_VAL_X(short ACC_VAL_X) {
        this.ACC_VAL_X = ACC_VAL_X;
    }

    public short getACC_VAL_Y() {
        return ACC_VAL_Y;
    }

    public void setACC_VAL_Y(short ACC_VAL_Y) {
        this.ACC_VAL_Y = ACC_VAL_Y;
    }

    public short getACC_VAL_Z() {
        return ACC_VAL_Z;
    }

    public void setACC_VAL_Z(short ACC_VAL_Z) {
        this.ACC_VAL_Z = ACC_VAL_Z;
    }

    public float getBAT_V() {
        return BAT_V;
    }

    public void setBAT_V(float BAT_V) {
        this.BAT_V = BAT_V;
    }
    /** !!!!!! getters and setters !!!!!! */

    private byte PVER;
    private byte MsgType;
    private byte Encrypt;
    private String VIN;
    private long RTC;
    private short EVID;
    private String IDENT;
    private byte GSM_SS;
    private byte GSM_RS;
    private short POS_SATS;
    private byte POS_VAL;
    private float POS_LAT;
    private float POS_LON;
    private int POS_HDG;
    private int POS_ALT;
    private int POS_SPD;
    private long ODOM;
    private short ACC_VAL_X;
    private short ACC_VAL_Y;
    private short ACC_VAL_Z;
    private float BAT_V;


    /**
     * 获取数据的String形式 -用于调试
     */
    public String getDataStr() {
        StringBuilder stringBuilder = new StringBuilder(130);
        stringBuilder.append(PVER);
        stringBuilder.append(",");
        stringBuilder.append(MsgType);
        stringBuilder.append(",");
        stringBuilder.append(Encrypt);
        stringBuilder.append(",");
        stringBuilder.append(VIN);
        stringBuilder.append(",");
        stringBuilder.append(RTC);
        stringBuilder.append(",");
        stringBuilder.append(EVID);
        stringBuilder.append(",");
        stringBuilder.append(IDENT);
        stringBuilder.append(",");
        stringBuilder.append(GSM_SS);
        stringBuilder.append(",");
        stringBuilder.append(GSM_RS);
        stringBuilder.append(",");
        stringBuilder.append(POS_SATS);
        stringBuilder.append(",");
        stringBuilder.append(POS_VAL);
        stringBuilder.append(",");
        stringBuilder.append(POS_LAT);
        stringBuilder.append(",");
        stringBuilder.append(POS_LON);
        stringBuilder.append(",");
        stringBuilder.append(POS_HDG);
        stringBuilder.append(",");
        stringBuilder.append(POS_ALT);
        stringBuilder.append(",");
        stringBuilder.append(POS_SPD );
        stringBuilder.append(",");
        stringBuilder.append(ODOM);
        stringBuilder.append(",");
        stringBuilder.append(ACC_VAL_X);
        stringBuilder.append(",");
        stringBuilder.append(ACC_VAL_Y);
        stringBuilder.append(",");
        stringBuilder.append(ACC_VAL_Z);
        stringBuilder.append(",");
        stringBuilder.append(BAT_V);
        stringBuilder.append(",");
        stringBuilder.append("\n");

        return stringBuilder.toString();
    }

    /**
     * 打印所有数据 -用于调试
     */
    @Override
    public String toString() {
        return "TrajectoryData: { " +
                "PVER=" + PVER +
                ", MsgType=" + MsgType +
                ", Encrypt=" + Encrypt +
                ", VIN='" + VIN + '\'' +
                ", RTC=" + RTC +
                ", EVID=" + EVID +
                ", IDENT='" + IDENT + '\'' +
                ", GSM_SS=" + GSM_SS +
                ", GSM_RS=" + GSM_RS +
                ", POS_SATS=" + POS_SATS +
                ", POS_VAL=" + POS_VAL +
                ", POS_LAT=" + POS_LAT +
                ", POS_LON=" + POS_LON +
                ", POS_HDG=" + POS_HDG +
                ", POS_ALT=" + POS_ALT +
                ", POS_SPD=" + POS_SPD +
                ", ODOM=" + ODOM +
                ", ACC_VAL_X=" + ACC_VAL_X +
                ", ACC_VAL_Y=" + ACC_VAL_Y +
                ", ACC_VAL_Z=" + ACC_VAL_Z +
                ", BAT_V=" + BAT_V +
                '}';
    }

}
